package net.brokenroad.gamma.server;

import java.util.*;

public class ServerOptions
{
	HashMap<String,Object> options;
	
	public ServerOptions()
	{
		options = new HashMap<String,Object>();
	}
	
	public int getInt(String key)
	{
		return Integer.parseInt(getString(key));
	}
	
	public String getString(String key)
	{
		return (String)getValue(key);
	}
	
	public Object getValue(String key)
	{
		return options.get(key);
	}
	
	public void put(String key, int value)
	{
		put(key, new Integer(value));
	}
	
	public void put(String key, Object value)
	{
		options.put(key, value);
	}

	/**
	 * Sets a value if and only if the server does not already
	 * have a value for that key.
	 * <p>
	 * Useful primarily for setting defaults that should not
	 * override values loaded from a settings file
	 * 
	 * @param key
	 *          The key to insert
	 * 
	 * @param value
	 * 					The value to insert at <code>key</code>
	 */
	public void ensureIsSet(String key, Object value)
  {
	  if(!options.containsKey(key))
	  	options.put(key, value);
  }
}
